package com.ruoyi.web.controller.university;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.UniversityMajorScore;
import com.ruoyi.system.service.IUniversityMajorScoreService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 大学专业分数线Controller
 * 
 * @author ruoyi
 */
@RestController
@RequestMapping("/university/major/score")
public class UniversityMajorScoreController extends BaseController
{
    @Autowired
    private IUniversityMajorScoreService universityMajorScoreService;

    /**
     * 查询大学专业分数线列表
     */
    @PreAuthorize("@ss.hasPermi('university:major:score:list')")
    @GetMapping("/list")
    public TableDataInfo list(UniversityMajorScore universityMajorScore)
    {
        startPage();
        List<UniversityMajorScore> list = universityMajorScoreService.selectUniversityMajorScoreList(universityMajorScore);
        return getDataTable(list);
    }

    /**
     * 导出大学专业分数线列表
     */
    @PreAuthorize("@ss.hasPermi('university:major:score:export')")
    @Log(title = "大学专业分数线", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(UniversityMajorScore universityMajorScore)
    {
        List<UniversityMajorScore> list = universityMajorScoreService.selectUniversityMajorScoreList(universityMajorScore);
        ExcelUtil<UniversityMajorScore> util = new ExcelUtil<UniversityMajorScore>(UniversityMajorScore.class);
        util.exportExcel(list, "大学专业分数线数据");
    }

    /**
     * 获取大学专业分数线详细信息
     */
    @PreAuthorize("@ss.hasPermi('university:major:score:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(universityMajorScoreService.selectUniversityMajorScoreById(id));
    }

    /**
     * 获取大学专业关联的分数线列表
     */
    @PreAuthorize("@ss.hasPermi('university:major:score:query')")
    @GetMapping(value = "/university-major/{universityMajorId}")
    public AjaxResult getScoresByUniversityMajor(@PathVariable("universityMajorId") Long universityMajorId)
    {
        return success(universityMajorScoreService.selectScoresByUniversityMajorId(universityMajorId));
    }

    /**
     * 获取指定年份和省份的分数线列表
     */
    @PreAuthorize("@ss.hasPermi('university:major:score:query')")
    @GetMapping(value = "/year/{enrollYear}/province/{province}")
    public AjaxResult getScoresByYearAndProvince(@PathVariable("enrollYear") Integer enrollYear, @PathVariable("province") String province)
    {
        return success(universityMajorScoreService.selectScoresByYearAndProvince(enrollYear, province));
    }

    /**
     * 新增大学专业分数线
     */
    @PreAuthorize("@ss.hasPermi('university:major:score:add')")
    @Log(title = "大学专业分数线", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UniversityMajorScore universityMajorScore)
    {
        if (!universityMajorScoreService.checkUniversityMajorScoreUnique(universityMajorScore))
        {
            return error("新增大学专业分数线失败，该分数线记录已存在");
        }
        return toAjax(universityMajorScoreService.insertUniversityMajorScore(universityMajorScore));
    }

    /**
     * 修改大学专业分数线
     */
    @PreAuthorize("@ss.hasPermi('university:major:score:edit')")
    @Log(title = "大学专业分数线", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UniversityMajorScore universityMajorScore)
    {
        if (!universityMajorScoreService.checkUniversityMajorScoreUnique(universityMajorScore))
        {
            return error("修改大学专业分数线失败，该分数线记录已存在");
        }
        return toAjax(universityMajorScoreService.updateUniversityMajorScore(universityMajorScore));
    }

    /**
     * 删除大学专业分数线
     */
    @PreAuthorize("@ss.hasPermi('university:major:score:remove')")
    @Log(title = "大学专业分数线", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(universityMajorScoreService.deleteUniversityMajorScoreByIds(ids));
    }
} 